package com.example.myjavafx.model;

import com.google.gson.annotations.SerializedName;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Users {
//    private final StringProperty name;
    @SerializedName("id")
    private final IntegerProperty id;
    @SerializedName("user_name")
    private final StringProperty user_name;
    @SerializedName("user_password")
    private final StringProperty user_password;
    @SerializedName("age")
    private final IntegerProperty age;

    public Users(String user_name, int age) {
        this.user_name = new SimpleStringProperty(user_name);
        this.age = new SimpleIntegerProperty(age);
        this.id = new SimpleIntegerProperty();
        this.user_password = new SimpleStringProperty();

    }
    public Users() {
        this.id = new SimpleIntegerProperty();
        this.user_password = new SimpleStringProperty();
        this.age = new SimpleIntegerProperty();
        this.user_name = new SimpleStringProperty();
    }

    public Users(int id, String user_name, String user_password, int age) {
        this.id = new SimpleIntegerProperty(id);
        this.user_name = new SimpleStringProperty(user_name);
        this.user_password = new SimpleStringProperty(user_password);
        this.age = new SimpleIntegerProperty(age);
    }
    // Getter 和 Property 方法（TableView绑定需要）
    public String getName() { return user_name.get(); }
    public StringProperty nameProperty() { return user_name; }
    public String getUser_name() { return user_name.get(); }
    public StringProperty user_nameProperty() { return user_name; }

    public String getUser_password() { return user_password.get(); }
    public StringProperty user_passwordProperty() { return user_password; }

    public int getId() { return id.get(); }
    public IntegerProperty idProperty() { return id; }

    public int getAge() { return age.get(); }
    public IntegerProperty ageProperty() { return age; }

    public void setUser_name(String user_name) { this.user_name.set(user_name); }
    public void setUser_password(String user_password) { this.user_password.set(user_password); }
    public void setId(int id) { this.id.set(id); }
    public void setAge(int age) { this.age.set(age); }

    // 辅助方法，用于从基本数据类型创建User对象
    public static Users fromJsonData(int id, String userName, String userPassword, int age) {
        return new Users(id, userName, userPassword, age);
    }
}
